<template>
  <div class="c-w100 c-pt28 c-ph24 c-bg-sgray">
    <div class="c-flex-row c-aligni-center c-bg-white c-br16 c-mb20" v-if="isRecommendVisit" @click="handleClickToRecommend(isRecommendVisit, 'isRecommendVisit', 'push')">
      <div class="c-flex-row c-justify-sb c-aligni-center c-w100 c-pv24 c-pl28 c-pr28">
        <div class="c-ww68 c-hh68 c-brp50">
          <img class="c-ww68 c-hh68 c-brp50" :src="$addXossFilter(require('@/assets/i/wap/recommend/share.png'))" alt="">
        </div>
        <div class="c-flex-grow1 c-w0 c-flex-column c-justify-sb c-ph30">
          <p class="c-fs24 c-fw600 c-text-ellipsis1">邀请好友访问</p>
          <p class="c-fs22 c-fc-gray c-text-ellipsis1 c-mt16">邀请好友访问，收获更多喜悦</p>
        </div>
        <div class="iconfont c-fs228 c-fc-sblack">&#xe635;</div>
      </div>
    </div>
    <div class="c-flex-row c-aligni-center c-bg-white c-br16 c-mb20" v-if="isRecommendOrder" @click="handleClickToRecommend(isRecommendOrder, 'isRecommendOrder', 'push')">
      <div class="c-flex-row c-justify-sb c-aligni-center c-w100 c-pv24 c-pl28 c-pr28">
        <div class="c-ww68 c-hh68 c-brp50">
          <img class="c-ww68 c-hh68 c-brp50" :src="$addXossFilter(require('@/assets/i/wap/recommend/place_order.png'))" alt="">
        </div>
        <div class="c-flex-grow1 c-w0 c-flex-column c-justify-sb c-ph30">
          <p class="c-fs24 c-fw600 c-text-ellipsis1">邀请好友下单</p>
          <p class="c-fs22 c-fc-gray c-text-ellipsis1 c-mt16">邀请好友下单，收获更多喜悦</p>
        </div>
        <div class="iconfont c-fs228 c-fc-sblack">&#xe635;</div>
      </div>
    </div>
    <div class="c-flex-row c-aligni-center c-bg-white c-br16" v-if="isRecommendBind" @click="handleClickToRecommend(isRecommendBind, 'isRecommendBind', 'push')">
      <div class="c-flex-row c-justify-sb c-aligni-center c-w100 c-pv24 c-pl28 c-pr28">
        <div class="c-ww68 c-hh68 c-brp50">
          <img class="c-ww68 c-hh68 c-brp50" :src="$addXossFilter(require('@/assets/i/wap/recommend/register.png'))" alt="">
        </div>
        <div class="c-flex-grow1 c-w0 c-flex-column c-justify-sb c-ph30">
          <p class="c-fs24 c-fw600 c-text-ellipsis1">邀请新用户注册</p>
          <p class="c-fs22 c-fc-gray c-text-ellipsis1 c-mt16">邀请新用户注册，收获更多喜悦</p>
        </div>
        <div class="iconfont c-fs228 c-fc-sblack">&#xe635;</div>
      </div>
    </div>
  </div>
</template>

<script>
  import { utilJs } from "@/utils/common.js";
  export default {
    name: 'RecommendCenter',
    data() {
      return {
        isRecommendVisit: 0,
        isRecommendBind: 0,
        isRecommendOrder: 0
      }
    },
    mounted() {
      setDocumentTitle("活动中心");
      this.getExistRecommend()
      this.wechatShare()
    },
    created() {
      utilJs.appShare(this);
    },
    methods: {
      handleClickToRecommend(recId, type, route) {
        this.$routerGo(this, route, {
          path: '/member/recommend/recommendIndex',
          query: {
            recId: type == 'isRecommendOrder' ? '' : recId,
            type: type == 'isRecommendOrder' ? 1 : ''
          }
        })
      },
      getExistRecommend() {
        utilJs.getMethod(global.apiurl + `activity/recommend/getExistRecommend`, res => {
          this.isRecommendVisit = res.isRecommendVisit;
          this.isRecommendBind = res.isRecommendBind;
          this.isRecommendOrder = res.isRecommendOrder;
          // 如果三种都无
          if (this.isRecommendVisit == 0 && this.isRecommendBind == 0 && this.isRecommendOrder == 0) {
            this.handleClickToRecommend(this.isRecommendOrder, 'isRecommendOrder', 'replace')
            return
          } else if (this.isRecommendVisit && this.isRecommendBind == 0 && this.isRecommendOrder == 0) {
            this.handleClickToRecommend(this.isRecommendVisit, 'isRecommendVisit', 'replace')
            return
          } else if (this.isRecommendVisit == 0 && this.isRecommendBind && this.isRecommendOrder == 0) {
            this.handleClickToRecommend(this.isRecommendBind, 'isRecommendBind', 'replace')
            return
          } else if (this.isRecommendVisit == 0 && this.isRecommendBind == 0 && this.isRecommendOrder) {
            this.handleClickToRecommend(this.isRecommendOrder, 'isRecommendOrder', 'replace')
            return
          }
        })
      },
      //分享
      wechatShare: function () {
        let title = '活动中心';
        let shareUrl = `${window.location.href.split("#")[0]}#${this.$route.path}?refereeId=${localStorage.getItem("userId")}`;
        let shareDesc = window.localStorage.getItem("shareDesc") || '点击查看详情';
        utilJs.wechatConfig(shareUrl, title, "", shareDesc, function () { }, true);
      },
      //手机端分享
      appShare: function () {
        let title = '活动中心';
        let shareUrl = `${window.location.href.split("#")[0]}#${this.$route.path}?refereeId=${localStorage.getItem("userId")}`;
        let shareDesc = window.localStorage.getItem("shareDesc") || '点击查看详情';
        utilJs.appShareTrue(title, "", shareUrl, shareDesc);
      }
    }
  }
</script>

<style lang="less" scoped>

</style>